# 复制
# https://www.bilibili.com/video/BV19T4y127Z2?p=9&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
import numpy as np
print("copy")

fruits = np.array(["Apple", "Pear", "Grapes", "Orange"])
print(fruits)

# copy() 深复制
print("# copy() ######################################")
v11 = fruits.copy()
v22 = fruits.copy()
v11[0] = "foo"
print(id(v11), v11 is fruits, v11.base is fruits, v11)
print(id(v22), v22 is fruits, v22.base is fruits,  v22)
print(id(fruits), fruits)

# 赋给其他值
v11 = np.arange(16)
print(v11)
print(v22)  # 不会改变
print(fruits) # 不会改变


# view() 浅复制
print("# view() ######################################")
v1 = fruits.view()
v2 = fruits.view()
v1[0] = "bar"
print(id(v1), v1 is fruits, v1.base is fruits, v1)
print(id(v2), v2 is fruits, v2.base is fruits, v2)
print(id(fruits), fruits)

# 赋给其他值
v1 = np.arange(16)
print(v1)
print(v2) # 不会改变
print(fruits) # 不会改变

#
v2.shape = 2, 2
print(v1)
print(v2)
print(fruits)

